﻿using Company.Database.Base.Entities;
using Company.Database.Base.Repositories;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Company.Database.SqlServer.Repositories
{
    class HL7PIDRepository: IHL7PIDRepository
    {
        private readonly SqlServerDbContext _context;
        public HL7PIDRepository(SqlServerDbContext context)
        {
            _context = context;
        }

        public async Task<int> DeleteAsync(HL7PID entity)
        {
            return await Task.Run(() =>
            {
                _context.Entry(entity).State = Microsoft.EntityFrameworkCore.EntityState.Deleted;
                return _context.SaveChanges();
            });
        }

        public async Task<List<HL7PID>> GetAllAsync()
        {
            return await Task.Run(() =>
            {
                return _context.HL7PID.ToList();
            });
        }

        public async Task<HL7PID> GetByIdAsync(int id)
        {
            return await _context.HL7PID.FindAsync(id) ?? new HL7PID();
        }

        public async Task<int> InsertAsync(HL7PID entity)
        {
            await _context.HL7PID.AddAsync(entity);
            return await _context.SaveChangesAsync();
        }

        public async Task<int> UpdateAsync(HL7PID entity)
        {
            return await Task.Run(() =>
            {
                _context.Entry(entity).State = Microsoft.EntityFrameworkCore.EntityState.Modified;
                return _context.SaveChanges();
            });
        }
    }
}
